<?php

namespace App\Http\Controllers\Home;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Models\Expert;
use App\Models\Teache;
use App\Models\Busines;
class ExpertController extends Controller
{
    //文章列表
    public function expert_list(){
        $data = Expert::select()->paginate(9);
        $teach = new Teache();
        $teach_data = $teach->orderby('id','asc')->get();
        return view('home.expert.expert_list',['data' => $data,'tea'=>$teach_data]);
    }
    //文章详情
    public function expert_details(Expert $expert,$id){
        $data = $expert->where('id',$id)->get();
        $tuijian = $expert->where('recomm','yes')->limit(10)->get(['id','title']);
        return view('home.expert.expert_details',['data'=>$data,'tuijian'=>$tuijian]);
    }
    //业务
    public function business(Busines $busines){
        $data = $busines->get();
        return view('home/expert/business',['data'=>$data]);
    }
    //业务详情
    public  function business_details(Busines $busines,$id){
        $data = $busines->where('id',$id)->get();
        $expert = new Expert();
        $tuijian = $expert->where('recomm','yes')->limit(10)->get(['id','title']);
        return view('home.expert.business_details',['data'=>$data,'tuijian'=>$tuijian]);
    }
    //搜索
    public function search(Request $request){
        $search = $request->all();
        $e_data = Expert::where('title','like','%'.$search['search'].'%')->paginate(9);
        $teach = new Teache();
        $teach_data = $teach->orderby('id','asc')->get();
        return  view('home.expert.expert_list',['data' => $e_data,'tea'=>$teach_data]);
    }
}
